<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/react.development.js"></script>
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/react-dom.development.js"></script>
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
</html>
<script type="text/babel">
    class Alert extends React.Component {
        constructor(props) {
            super(props)
        }
        UNSAFE_componentWillReceiveProps() {
            console.log("========UNSAFE_componentWillReceiveProps========")
        }
        render() {
            return (
                <div className="mt-4 alert alert-danger">
                    当前数值为: {this.props.num}
                </div>
            )
        }
    }

    class App extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                num: 0
            }
            console.log("========constructor========");
        }
        increment = () => {
            this.setState((state) => ({ num: state.num + 1 }))
        }
        UNSAFE_componentWillMount() {
            console.log("========UNSAFE_componentWillMount========")
        }
        componentDidMount() {
            console.log("========componentDidMount========")
        }
        render() {
            return (
                <div className="container">
                    <Alert num={this.state.num} />
                    <button onClick={this.increment} className="btn btn-outline-info">增加</button>
                    <div onClick={this.death} className="ml-2 btn btn-outline-danger">销毁组件</div>
                </div>
            )
        }
    }
    ReactDOM.createRoot(document.getElementById("app")).render(<App />)
</script>